/*!
 * 树形视图控件.
 * ecp.qzz.ui.treeview.js
 * 创建：QZZ
 * 日期：2014-03-01
 */
define(["qzz.frame","qzz.treelist", "qzz.icheckbox"], function() {	
	
	var qzz = window.qzz;
	
	qzz.space("ui");
	
	qzz.ui.treeview = qzz.Class(qzz.ui.frame, {
		/**
		 * 创建函数.
		 */
		_create:function() {
			this.base();
		    this.className = "TreeView";
		    this.logInfo("treeView.create");
		    //创建树形控件
		    this.treeList = new qzz.treelist();	
		    //行标
		    this.rowIndex = 0;
		    //可见行数量
		    this.showCount = this._getNumberValue(this.getOption().showCount, 6);
		    //可见行顶节点
		    this.topNode = null;
		    //可见行顶节点序号
		    this.topIndex = 0;
		    //可见行主底节点
		    this.bottomNode = null;
		    //行高
		    this._rowHeight = this._getNumberValue(this.getOption().rowHeight, 17);
		    //流动条高
		    this.scrollHeight = 16;
		    //视图高
		    this.getOption().height = this._getNumberValue(this.getOption().height,
		    		this._rowHeight * this.showCount + this.scrollHeight);
		    //视图宽
		    //this.getOption().width = 200;
		    //渲染状态
		    this.rendered = false;
		    //自适应高标志
		    this.autoHeight = this.getBooleanValue(this.getOption().autoHeight, false);
		    //初始化数据
		    var data = this.getOption().data;
		    //配置树方式.
		    this.treePidData = this.getBooleanValue(this.getOption().treePidData, false);
		    if(this.getOption().pidkey != null || this.getOption().parentKeyId != null) {
		       this.treePidData = true;	
		    }		    
		    this.treeList.getOption().fullPath = this.getOption().fullPath;
		    this.treeList.getOption().idkey = this.getOption().idkey;
	    	this.treeList.getOption().capkey = this.getOption().capkey;
		    //初始化树构造方式.
	    	if(this.treePidData) {
	    		this.treeList.setIDPID(this.getOption().treeId || this.getOption().idkey, this.getOption().parentKeyId || this.getOption().pidkey);
	    		this.treeList.initSort = false;
	    	} else {
	    		var key = this.getOption().treeId;
	    		if(key == null) {
	    			key = this.treeList.getOption().idkey || "bm";
	    		}
	    		this.treeList.setItemCode(key);
	    	}
	    	
		    if(this.isNotEmpty(data)) {
		    	var _this = this;		    	
		    	this.treeList.setItemList(data, function() {
		    		_this.setLeafOnly(_this.getOption().leafOnly === true);	
		    	});
		    	this.treeList.first();
		    	this.topNode = this.treeList.getCurNode();
	    	}
		    data = null;
	    	//选择
	    	if(this.isNotEmpty(this.getOption().checkFlag)) {
	    		var cps = this.getOption().checkFlag;
	    		if(cps.indexOf("p") >= 0) {
	    			this.treeList.autoCheckType.autoCheckAllParent = true;
	    		}
	    		if(cps.indexOf("s") >= 0) {
	    			this.treeList.autoCheckType.autoCheckAllChild = true;
	    		}
	    		if(cps.indexOf("b") >= 0) {
	    			this.treeList.autoCheckType.autoCheckBrother = true;
	    		}
	    		if(cps.indexOf("e") >= 0) {
	    			this.treeList.autoCheckType.autoCheckAllParentExt = true;
	    		}
	    	}
	    	//取消选择
	    	if(this.isNotEmpty(this.getOption().unCheckFlag)) {
	    		var cps = this.getOption().unCheckFlag;
	    		if(cps.indexOf("p") >= 0) {
	    			this.treeList.autoCheckType.autoUnCheckAllParent = true;
	    		}
	    		if(cps.indexOf("s") >= 0) {
	    			this.treeList.autoCheckType.autoUnCheckAllChild = true;
	    		}
	    		if(cps.indexOf("b") >= 0) {
	    			this.treeList.autoCheckType.autoUnCheckBrother = true;
	    		}
	    		if(cps.indexOf("e") >= 0) {
	    			this.treeList.autoCheckType.autoUnCheckAllParentExt = true;
	    		}
	    	}
		    this.multiSelect = this.getBooleanValue(this.getOption().multiselect, this.getOption().multiSelect);
		    if(this.isEmpty(this.multiSelect)) {
		    	this.multiSelect = false;
		    }
		    this.treeList.multiSelect = this.multiSelect;
	    },
	    /**
	     * 渲染函数.
	     */
	    _render:function() {
	    	this.base();
	    	this.logInfo("treeView.render");
	    	//显示列表
	    	this.listTab = this.createElement("table");
	    	this.setStyle(this.listTab, "component_ui_listview_list_table");
	    	this.listTab.style.width = "100%";
	    	this.listTab._this = this;
	    	//容器
	    	this.listDiv.appendChild(this.listTab);
	    	this.isSelect = true;
	    	this.maxWidth = 0;
	    	this.refresh();
	    },
	    _onTreeCheckBoxClick:function(ev) {
			var _this = this._this;
			var cNode = this._cNode;
			if(!cNode.checkState) {
		        _this.treeList.setSelect(cNode);
		    } else {
		    	_this.treeList.setUnSelect(cNode);
		    }
			//复选择选择事件.
			if(typeof _this.onCheckChanged === "function") {
				try {
					_this.onCheckChanged(this._cNode, this._cNode.checkState);		    						
				} catch(e) {
					_this.logInfo("[onCheckChanged] error:" + e.message + e.stack);
				}
			}
			_this.trigger("onSelectRow",[this._cNode, this._cNode.checkState]);
			_this.trigger("onCheckChanged", [this._cNode, this._cNode.checkState]);
			//换行的时候不用刷新
			//if(cNode.recNo == _this.treeList.getCurNode().recNo) {
		    _this.refresh();
			//}
			_this = null;
		},
		refreash:function() {
			this.refresh();
		},
	    /**
	     * 刷新视图.
	     */
	    refresh:function(){
	    	if(!this._update) return false;
	    	this.beginUpdate();
	    	var hsh = this.getHScrollHeight();
	    	//计算行数
	    	if(!this.autoHeight) {
	    	    this.showCount = Math.round((this._getRectHeight() - hsh)/this._rowHeight) + 1;
	    	}
	    	var rlen = this.listTab.rows.length;
	    	var len = this.treeList.getVisibleCount();
	    	var mxlen = this.showCount < len ? this.showCount : len;
	    	var cNode = this.topNode;
	    	var td, row, i;
	    	this.rowIndex = -1;
	    	var curNode = this.treeList.curNode;
	    	this.treeList.beginUpdate();
	    	this.treeList.select(cNode);
	    	var pointWidth = 16;
	    	//循环刷新视图
	    	for(i = 0; i <= mxlen && cNode != null; i ++) {
	    		row = this.listTab.rows[i];
	    		if(row == null) {
	    			row = this.listTab.insertRow(i);
	    		}	    		
	    		td = row.cells[0];
	    		var isLast = (cNode.index >= cNode.pNode.count - 1);
	    		if(td == null) {
	    			td = row.insertCell(0);
	    			//插入节点列表
	    			nodeTable = this.createElement("table");
	    			nodeTable.border = 0;
	    			nodeTable.cellPadding = 0;
		    		nodeTable.cellSpacing = 0;
		    		td.nodeTable = nodeTable;
		    		td.nodeR = nodeTable.insertRow(0);
		    		td.nodeR.style.height = this._rowHeight + "px";
		    		//+-号单元格
	    			td.pointTd = td.nodeR.insertCell(0);
	    			td.pointTd.style.width = pointWidth+"px";
	    			td.pointTd._this = this;
	    			td.pointDiv = this.createElement("div");
	    			td.pointDiv.style.width = pointWidth+"px";	
	    			td.pointDiv.style.height = this._rowHeight +"px";
	    			td.pointTd.appendChild(td.pointDiv);    			
	    			td.checkTd = td.nodeR.insertCell(1);
	    			td.checkTd.style.width = pointWidth+"px";
	    			td.checkBox = new qzz.ui.input.checkbox();
	    			td.checkBox._this = this;
	    			td.checkBox.bind("onClick", this._onTreeCheckBoxClick, true);
	    		    //this.setStyle(td.checkBox, "checkBox");
	    		    td.checkTd.appendChild(td.checkBox.getContainer());
	    			td.textTd = td.nodeR.insertCell(2);
	    			td.textTd._this = this;	
	    			//添加到行列表中
	    			td.appendChild(nodeTable);
	    		} else {
	    			var clen = td.nodeR.cells.length;
	    			while(clen > 3) {
	    				td.nodeR.deleteCell(0);
	    				clen--;
	    			}
	    		}
	    		var cw = 0;
	    		if(this.multiSelect) {
	    			td.checkTd.style.display = "";
	    			td.checkBox.setCheck(cNode.checkState);	    			
	    			td.checkBox._cNode = cNode;
	    			cw = pointWidth;
	    			if(cNode.enable) {
	    				td.checkBox.setDisable(false);
	    			} else {
	    				td.checkBox.setDisable(true);
	    			}
	    		} else {
	    			td.checkTd.style.display = "none";
	    		}
    			td.textTd._node = cNode;
	    		var stylePrefix = "";
	    		if(isLast) {
	    			stylePrefix = "_last";
	    		} else {
	    			stylePrefix = "_center";
	    		}
    			//控制节点样式
	    		if(cNode.recNo == curNode.recNo) {
	    			if(this.focus) {
	    			    this.setStyle(td.textTd, "component_ui_treeview_td_over");
	    			} else {
	    				this.setStyle(td.textTd, "component_ui_treeview_td_nofocus_over");
	    			}
	    			this.rowIndex = i;
	    		} else {	    		
	    		    this.setStyle(td.textTd, "component_ui_treeview_td");
	    		}	    		
    			td.style.paddingLeft = "4px";
	    		if(cNode.count > 0) {
	    			//展开，收缩样式
	    			if(cNode.expanded) {
	    				this.setStyle(td.pointDiv, "component_ui_treeview_node_expand" + stylePrefix);
	    			} else {
	    				this.setStyle(td.pointDiv, "component_ui_treeview_node_collapse" + stylePrefix);
	    			}
	    			td.pointTd.node = cNode;	    			
	    			//添加点击事件
	    			td.pointTd.onclick = function() {
	    				if(this.node.expanded) {
	    				    this.node.collapse();
	    				} else {
	    					this.node.expand();
	    				}	    				
	    				this._this.isSelect = false;
	    				this._this.refresh();
	    			}
	    		} else {
	    			this.setStyle(td.pointDiv, "component_ui_treeview_node" + stylePrefix);	    			
	    			td.pointTd.onclick = null;	    			
	    		}	    		
	    		if(cNode.enable === false) {
	    			this.addStyle(td.textTd, "component_ui_treeview_td_disable");
	    		}
	    		var curWidth = cNode.level * pointWidth + pointWidth + cw;
	    		var tmpNode = cNode.pNode;
	    		for(var l = 0; l < cNode.level; l++) {
	    			var cell = td.nodeR.insertCell(0);
	    			cell.style.width = pointWidth+"px";
	    			if(tmpNode.index >= tmpNode.pNode.count - 1) {
	    				this.setStyle(cell, "component_ui_treeview_box_last");
	    			} else {
	    				this.setStyle(cell, "component_ui_treeview_box_center");
	    			}
	    			tmpNode = tmpNode.pNode;
	    		}
	    		var cText = cNode.text;
	    		if(this.hasbind("onItemDraw")) {
	    		    cText = this.trigger("onItemDraw", [this.treeList, td.textTd, cText]);	
	    		}
    			this._setHtml(td.textTd, cText);
	    		//处理缩进
	    		var tw = this.getTextWidth(cNode.text + 25);
	    		if(this.maxWidth < curWidth + tw) {
	    			this.maxWidth = curWidth + tw;
	    		}
	    		td.textTd.onclick = this.doSelect;	    		
	    		if(this.treeList.next()) {
	    			cNode = this.treeList.curNode;
	    		} else {
	    			cNode = null;
	    		}
	    	}	
	    	if(this.maxWidth > 0) {
	    	    this.listTab.style.width = (this.maxWidth + 10) + "px";
	    	}
	    	//删除多余的行
	    	for (var j = rlen - 1; j >= i; j--) {
	            this.listTab.deleteRow(j);
	        }
	    	this.bottomNode = this.treeList.curNode;
	    	this.treeList.endUpdate(false);	    	
	    	this.treeList.select(curNode);
	    	rlen = null;
	    	//刷新滚动条
	    	if(this.showCount - 1 < len) {
	    	    this.scrollBar.setScrollCount(len, this.showCount - 1);
	    	    this.setVScrollHide(false);
	    	} else {
	    		this.scrollBar.setScrollCount(0, 0);
	    		this.setVScrollHide(true);
	    	}
	    	this.rendered = true;
	    	this.endUpdate();
	    },
	    /**
	     * 处理选择事件.
	     * @param ev 事件对象
	     */
	    doSelect : function(ev) {
	    	var _this = this._this;
	    	if(_this.isSelect) {
		    	var cNode = this._node;
		    	if(_this.treeList.curNode.recNo != cNode.recNo) {
		            _this.treeList.select(cNode);
		            this.tmpClassName = "";
		            _this.refresh();
		    	}
		    	if(typeof _this.onSelect == "function" && _this.treeList.isEnableCheck() === true) {
		    		 _this.onSelect(_this.treeList.curNode);
		    	}
	    	}
	    	_this.isSelect = true;
	    },
	    /**
	     * 处理滚动事件.
	     * @param scrollIndex 滚动序号 
	     * @param scrollCount 滚动数量
	     */
	    doScroll:function(scrollIndex, scrollCount) {
	    	if(scrollCount !== 0) {			    
	    		var _this = this;	    	
		    	_this.topIndex = scrollIndex;
		    	_this.treeList.beginUpdate();
		    	var tmpNode = _this.treeList.curNode;
		    	//计算定位位置
		    	_this.treeList.select(_this.topNode);
		    	if(scrollCount > 0) {
		    		for(var i = 0; i < scrollCount; i++) {
		    			_this.treeList.next();
		    		}
		    	} else {
		    		for(var i = 0; i > scrollCount; i--) {
		    			_this.treeList.prior();
		    		}
		    	}
		    	_this.topNode = _this.treeList.curNode;
		    	_this.treeList.select(tmpNode);
		    	tmpNode = null;
		    	_this.treeList.endUpdate();			    	
		        _this.refresh();
		        _this = null;
		    }	
	    },
	    /**
	     * 处理鼠标滚动事件.
	     * @param ev 事件对象
	     */
	    doMouseWheel:function(ev) {
	    	this.base();
	        var ent = ev;
	        var scint = 0;
	        //处理浏览器兼容问题
	        if (ent.wheelDelta) {
	            scint = ent.wheelDelta;
	        } else {
	            scint = ent.detail * (-1);
	        }
	        var _this = this;
	        //跟据实际情况调用滚动函数
	        if (scint > 0) {
	        	_this.scrollBar.scrollPrior();
	        } else {
	        	_this.scrollBar.scrollNext();
	        }
	        _this = null;
	        ent.returnValue = false;
	        ent = null;
	        scint = null;
	        return false;
	    },
	    /**
	     * 处理按键按下事件.
	     * @param ev 事件对象
	     * @param key 按键号
	     */
	    doKeyDown:function(ev, key){
	    	var ent = ev;
	    	if (key == this.keyBoard.UP) {
	    		//按向上键
	    		this.prior();
	        } else if (key == this.keyBoard.DOWN) {
	        	//按向下键
	        	this.next();
	        }
	    	ent = null;
	    	key = null;
	    	_this = null;
	    },
	    addFilterText:function(selItem, filter, callBack) {
	    	this.treeList.addFilterText(selItem, filter, callBack);
	    },
	    clearFilterText:function(callBack) {
	    	this.treeList.clearFilterText(callBack);
	    },
	    setFiltered:function(filtered, callBack) {
	    	this.treeList.setFiltered(filtered, callBack);
	    },
	    isFiltered:function() {
	    	return this.treeList.filtered
	    },
	    /**
	     * 处理按键弹起事件.
	     * @param ev 事件对象
	     * @param key 按键号
	     */
	    doKeyUp:function(ev, key){
	    	if(key == this.keyBoard.ENTER && typeof this.onSelect == "function") {	   
	    		//回车事件
				var item = this.treeList.getCurNode();
				if(item != null) {
				    this.onSelect(item);
				}				
				item = null;
				this.logInfo("key up");
			}  
	    },
	    /**
	     * 定位第一行.
	     */
	    first:function() {
	    	this.treeList.first();
	    	this.topNode = this.treeList.getCurNode();
	    	this.refresh();
	    },
	    /**
	     * 上一行.
	     */
	    prior:function() {
	    	this.treeList.prior();
	    	this._scrollToFocus();
	    },
	    /**
	     * 下一行.
	     */
	    next:function() {
	    	this.treeList.next();
	    	this._scrollToFocus();
	    },
	    /**
	     * 定位最后一行.
	     */
	    last:function() {
	    	this.treeList.last();
	    	this._scrollToFocus();
	    },
	    /**
	     * 添加行节点.
	     * @param node 节点
	     * @param pNode 父节点
	     * @param focus 设为焦点
	     */
	    addNode:function(node, pNode, focus) {
	    	if(node instanceof qzz.treenode) {
	    		//如果是节点，直接添加
	    		return this.treeList.addNode(node, pNode, focus);
	    	} else {
	    		//如果是字符串，或json对象则改创建新节点并添加
	    		if(typeof node == "string") {
	    			var cn = new qzz.treenode();
	    			cn.text = node;
	    			return this.treeList.addNode(cn);
	    		} else if(typeof node == "object") {
	    			var cn = new qzz.treenode();
	    			cn.text = node.text;
	    			cn.id = node.id;
	    			return this.treeList.addNode(cn);
	    		}
	    	}
	    },
	    /**
	     * 插入节点.
	     * @param index 下标
	     * @param node 节点
	     * @param pNode 父节点
	     * @param focus 设为焦点
	     */
	    insertNode:function(index, node, pNode, focus) {
	    	if(node instanceof qzz.treenode) {
	    		//如果是节点，直接添加
	    		return this.treeList.insertNode(index, node, pNode, focus);
	    	} else {
	    		//如果是字符串，或json对象则改创建新节点并添加
	    		if(typeof node == "string") {
	    			var cn = new qzz.treenode();
	    			cn.text = node;
	    			return this.treeList.insertNode(index, cn);
	    		} else if(typeof node == "object") {
	    			var cn = new qzz.treenode();
	    			cn.text = node.text;
	    			cn.id = node.id;
	    			return this.treeList.insertNode(index, cn);
	    		}
	    	}
	    },
	    /**
	     * 删除节点.
	     * @param index 序号
	     * @param pNode 父节点
	     */
	    delNode:function(index, pNode) {
	    	return this.treeList.delNode(index, pNode);
	    },
	    /**
	     * 设置只能选择叶子节点.
	     */
	    setLeafOnly:function(state, callBack) {
	    	this.treeList.each(function(node) {
	    		if(node.count > 0) {
	    			node.enable = state !== true;
	    		}
	    	}, callBack);
	    },
	    value:function(itemList, callBack) {
	    	this.setItemList(itemList, callBack);
	    },
	    /**
	     * 设置列表.
	     * @param itemList 列表数组
	     * @param key 字段
	     */
	    setItemList:function(itemList, callBack) {
	    	var _this = this;
	    	this.topNode = null;
	    	this.treeList.setItemList(itemList, function() {
	    		_this.setLeafOnly(_this.getOption().leafOnly === true, function() {
	    			if(_this.topNode != null) {
		    		    _this.refresh();
		    		}
	    			if(typeof callBack == "function") {
	    				callBack();
	    			}
		    		_this = null;
	    		});	    		
	    	});
	    	this.treeList.first();
	    	this.topNode = this.treeList.curNode;
	    	this.topCount = 0;
	    	this.maxWidth = 0;
	    	this.refresh();
	    },
	    /**
	     * 设置树层次编码.
	     */
	    setItemCode:function(key) {
	    	this.treeList.setItemCode(key);
	    },
	    /**
	     * 设置树层次ID，PID.
	     */
	    setIDPID:function(id, pid) {
	    	this.treeList.setIDPID(id, pid);
	    },
	    /**
	     * 处理宽高变更事件.
	     */
	    _doResize:function(el) {
	    	this.base(el);
	    	if(this.rendered && this._update) {
		    	this.refresh();
		    	if(this.autoHeight) {
		    		if(this.showCount == null) {
			    		this.showCount = 0;
			    	}
		    		this.getOption().height = this._rowHeight * this.showCount + this.scrollHeight;
			    }
	    	}
	    },	
	    /**
	     * 处理去焦点事件.
	     */
	    doBlur:function() {
	    	this.base();
	    	this.refresh();
	    },
	    /**
	     * 处理获取焦点事件.
	     */
	    doFocus:function() {
	    	this.base();
	    	this.refresh();
	    },
	    getCurNode:function() {
	    	return this.treeList.getCurNode();
	    },
	    setMultiSelect:function(value) {
	    	this.getOption().multiselect = value;
	    	this.multiSelect = value;
	    },
	    getSelectedData:function() {
	    	if(this.multiSelect) {
	    		 var cn = this.treeList.getCurNode();
	    		 this.treeList.first();
				 var selDatas = [];
				 while(!this.treeList.isEof()) {
					 if(this.treeList.isSelected()) {
						 selDatas.push(this.getCurNode().data);
					 }
					 this.treeList.next(true);
				 }
				 return selDatas;
	    	} else {
	    		return this.treeList.getCurNode().data;
	    	}
	    },
	    /**
	     * 通过id设置选择值.
	     */
	    setSelectById:function(ids, callBack) {
	    	this.treeList.setSelectById(ids, callBack);
	    },
	    /**
	     * 通过text设置选择值.
	     */
	    setSelectByText:function(texts, callBack) {
	    	this.treeList.setSelectByText(texts, callBack);
	    },
	    /**
	     * 判断字符串在树上是否存在.
	     */
	    indexOfText:function(text) {
	    	return this.treeList.indexOfText(text);
	    },
	    
	    locate:function(text) {
	    	if(this.treeList.locate(text)) {
	    		this._scrollToFocus();
	    		return true;
	    	}
	    	return false;
	    },	
	    
	    getDisplay:function(node) {
	    	return this.treeList.getDisplay(node);
	    },
	    
	    getValue:function(node) {
	    	return this.treeList.getValue(node);
	    },
	    getAllCount:function() {
	    	return this.treeList.getAllCount();
	    },
	    unCheckAll:function(callBack) {
	    	this.treeList.unCheckAll(callBack);
	    },
	    checkAll:function(callBack) {
	    	this.treeList.checkAll(callBack);
	    },
	    /**
	     * 移到第一节点.
	     */
	    first:function() {
	    	this.treeList.first();
	    	this.topNode = this.treeList.getCurNode();
	    	if(this.topNode.level >= 0) {
	    	    this.topNode.scrIndex = 1;
	    	}
	    	this.beginUpdate();
	    	this.scrollBar.setScrollIndex(0);
	    	this.endUpdate(false);
	    	this.refresh();
	    },
	    /**
	     * 返回当前滚动的行.
	     */
	    getScrollIndex:function() {
	    	if(this.topNode != null) {
	    		return this.topNode.scrIndex;
	    	} else {
	    		return 1;
	    	}
	    },
	    /**
	     * 滚动到第几列.
	     * @param index 顶序号
	     */
	    scrollToIndex:function(index) {
	    	if(index > 1) {
	    		if(index > this.getAllCount()) {
	    			index = this.getAllCount();
	    		}
	    		var re = true;
	    		if(index > 1) {
		    		this.treeList.beginUpdate();
		    		var cn = this.treeList.getCurNode();
		    		var dcount = 0
		    		this.treeList.select(this.topNode);
		    		if(index > this.topNode.scrIndex) {
			    		while(!this.treeList.isEof()) {
			    			if(index == this.treeList.getIndex()) {
			    				break;
			    			} else if(index < this.treeList.getIndex()) {
			    				re = false;
			    				break;
			    			}
			    			dcount ++;
			    			this.treeList.next();
			    		}
		    		} else {		    			
		    			while(!this.treeList.isBof()) {
			    			if(index == this.treeList.getIndex()) {
			    				break;
			    			} else if(index > this.treeList.getIndex()) {
			    				re = false;
			    				break;
			    			}
			    			dcount --;
			    			this.treeList.prior();
			    		}
		    		}
		    		this.treeList.select(cn);
		    		this.treeList.endUpdate(false);
		    		if(re === true) {
		    		    this.scrollBar.setScrollIndex(this.scrollBar.scrollIndex + dcount);
		    		}
		    		this.refresh();
	    		} else {
	    			this.first();
	    		}
	    	} else {
	    		this.first();
	    	}
	    },
	    
	    _scrollToFocus:function() {
    		if(this.treeList.curNode.scrIndex < this.topNode.scrIndex) {
    			var scindex = this.scrollBar.scrollIndex;
    			var k = 0;
    			var cNode = this.treeList.curNode;	    			
    			this.treeList.curNode = this.topNode;
    			while(this.treeList.curNode.recNo != cNode.recNo && !this.treeList.isBof()) {
    				this.treeList.prior();
    				if(!this.treeList.isBof()) {
    				    scindex--;
    				}
    			}
    			this.scrollBar.setScrollIndex(scindex);
    		} else if(!this.treeList.isEof() && this.treeList.curNode.scrIndex >= this.bottomNode.scrIndex) {
    			var scindex = this.scrollBar.scrollIndex;
    			var k = 0;
    			var cNode = this.treeList.curNode;	    			
    			this.treeList.curNode = this.bottomNode;
    			while(this.treeList.curNode.recNo != cNode.recNo && !this.treeList.isEof()) {
    				this.treeList.next();
    				if(!this.treeList.isEof()) {
    				    scindex++;
    				}
    			}
    			this.scrollBar.setScrollIndex(scindex + 1);
    		}
	    	this.refresh();
	    }
	});
	
	/**
	 * 树形控件.
	 */
	_bindRenderFunc("qzztreeview", qzz.ui.treeview);

	return qzz.ui.treeview;
});
	